import {Component} from '@angular/core';
import {NavController, NavParams, LoadingController,AlertController } from 'ionic-angular';
import _ from 'lodash';
import request from 'superagent';
import {Backend} from '../../providers/backend';
import {ImagePipe} from '../../pipes/pipes';
import {PopoverPage} from './tab-popover';
@Component({
  templateUrl: 'build/pages/tab-events/tab-previous-list.html',
  pipes: [ImagePipe],

})
export class TabList {

  static get parameters() {
    return [[NavController], [NavParams], [LoadingController], [Backend],[AlertController]];
  }

  constructor(nav, params, loadingController, backend,alertController) {
    this.nav = nav;
    this.alertCtrl=alertController;

    this.params = params;
    this.backend = backend;
    this.loadingController = loadingController;
    this.item = params.get('item').item;
    this.id = params.get('item').id;
    this.img1 = 'asset/img/1-2.png';
    this.img = 'asset/img/1-3.png';
    console.log(this.item);
    this.img2 = 'asset/img/2_3.png';
    this.img3 = 'asset/img/1-1.png';
    this.result = [];
    this.inTheaters = [];
    this.movie = [];
    this.itemm = undefined;
    // let loader = this.loadingController.create({
    //   content: 'Please wait...'
    // });
    // loader.present();
    this.backend.dsFind({
      e: params.data.item.item.id + '-timelineEvent-edit'
    }).then((result) => {
      console.log(result);
      if (this.id == '2') {
        this.result = result.openingSpeech;
        this.result=_.sortBy(this.result, ['sort']);
        this.title='OPENING SPEECH';
      } else {
        this.result = result.keynoteSpeech;
        this.result=_.sortBy(this.result, ['sort']);
        this.title='KEYNOTE SPEECH';
      }
      console.log(this.result,'8989');
      // loading.dismiss();
    });
  }

  viewMore(item) {
    if (this.itemm == undefined) {
      this.itemm = 2;
      item.app=2;
    } else {
      this.itemm = undefined;
      item.app=undefined;
    }
  }
  download(path){
    this.backend.fileDownload(path);
  }
  presentPopover(videos) {
     console.log(videos,'5656');
  //     let alert = this.alertCtrl.create({
                  
  //               message:`
  //   <div class="video-item">
  //           <div>
  //           <video  autoplay="autoplay" class="video-player">
  //             <source src="`+video.video+`" type="video/mp4" />
  //           </video>
            
  //           <div class="video-cover" (click)="playVideo(`+video+`)" tappable>
  //             <img src='asset/img/1-4.png' *ngIf="isAndroid &&!video.play">
              
  //           </div>
  //           </div>
            
  //         </div>
  // `,
  //               // buttons: ['CLOSE']
  //             });
  //       alert.present();
    // let popover = this.popoverController.create(PopoverPage, { 'videos': videos });
    // popover.present({
    //   ev: { 'videos': videos }
    // });
    this.nav.rootNav.push(PopoverPage, { videos: videos });
  }

}
